<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Activity extends DQ_Controller 
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->Model('thread_model');
        $threadInfo = $this->thread_model->getThreadDetail();

        if($threadInfo['error'] === 0)
        {
            $joined = $this->thread_model->getJoinedPeople();

            $joined_uid = array();
            if($joined['error'] == 0)
            {
                foreach($joined['data'] as $value)
                {
                    $joined_uid[] = $value['uid'];
                }
            }

            if($joined_uid)
            {
                $threadInfo['data']['joined'] = $joined_uid;
            }

            $this->load->Model('user_model');
            $authorInfo = $this->user_model->getUserInfoDetail(array('uid'=>$threadInfo['data']['thread']['authorid']));

            if($authorInfo['error'] === 0 )
            {
                $threadInfo['data']['authorInfo'] = $authorInfo['data'];
            }
            //用户数据有问题
            else
            {
                error_page(USER_ERROR);
                return;
            }

            $this->load->view('thread/index',$threadInfo['data']);
        }
        else
        {
            error_page();
            return;
        }
    }

    public function add()
    {
        if(!$this->session->userdata('uid'))
        {
            $this->session->set_userdata('next',site_url('activity/add'));
            redirect('login', 'refresh' );
        }
        else
        {
		    $this->load->view('thread/add',array('city'=>getCity(),'isMobile'=>isMobile()));
        }
    }

}
